/*
 *  Copyright 2009 Advanced Industrial Science and Technology (AIST).
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/*! \file
 *  \brief
 *  breadth first search sample
 */ 

#include <thrust/graph/adjacency_list.hpp>
#include <thrust/graph/random.hpp>
#include <thrust/graph/breadth_first_search.hpp>
using namespace thrust;

#include <iostream>
using namespace std;

void test( unsigned int N, unsigned int M, unsigned int seed)
{
  typedef adjacency_list<directedS,disallow_parallelS> graph_t;

  typedef thrust::random::default_random_engine  gen;
  
  clock_t start, finish;
  
  start =clock();
  graph_t g( N, M);
  thrust::generate_random_graph<gen>( g, N, M, false, false, seed);
  finish =clock();
  
  std::cout <<(double)(finish - start)/(double)CLOCKS_PER_SEC 
	    <<" ";
  
  // breadth first search
  bfs_visitor vis;
  start =clock();
  breadth_first_search( g, 0, vis);
  finish =clock();
  
  std::cout <<(double)(finish - start)/(double)CLOCKS_PER_SEC
	    << std::endl;
}

int main( int argc, char* argv[])
{
  
  unsigned int N;
  unsigned int M;
  unsigned int seed =1;
  
  if ( argc ==3){
    N =atoi( argv[1]);
    M =atoi( argv[2]);
  }
  else if( argc ==4){
    N =atoi( argv[1]);
    M =atoi( argv[2]);
    seed =atoi( argv[3]); 
  }
  else {
    std::cerr <<"usage: bfs nodes edges seed" <<std::endl;
    exit( 1);
  }

  test( N, M, seed);

  return 0;
}
